﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;

namespace shuatibao.Tool
{
    public class LogManager
    {

        #region 插入数据
        public static void insertIntoDiary(string info, string name, string openid, string back)
        {
            // 连接数据库
            SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
            sqlcon.Open();
            string StrInsert = "";
            StrInsert = "insert into wechatAES(info,name,openid,datetime,back) values(@info,@name,@openid,@datetime,@back)";
            SqlCommand cmd = new SqlCommand(StrInsert, sqlcon);
            // 添加参数并且设置参数值
            // 1. 作者id
            cmd.Parameters.Add("@info", SqlDbType.VarChar, 50000);
            cmd.Parameters["@info"].Value = info == null ? "":info;

            cmd.Parameters.Add("@name", SqlDbType.VarChar, 50000);
            cmd.Parameters["@name"].Value = name == null ? "" : name;

            cmd.Parameters.Add("@openid", SqlDbType.VarChar, 50000);
            cmd.Parameters["@openid"].Value = openid == null ? "" : openid;

            cmd.Parameters.Add("@datetime", SqlDbType.VarChar, 50000);
            cmd.Parameters["@datetime"].Value = DateTime.Now.ToString();

            cmd.Parameters.Add("@back", SqlDbType.VarChar, 50000);
            cmd.Parameters["@back"].Value = back == null ? "" : back;

            // 执行插入数据的操作
            cmd.ExecuteNonQuery();
            sqlcon.Close();

        }
        #endregion
    }
}